﻿<div class="ld-tabs">
    <ul>
        <li class="k-state-active">留言列表</li>
    </ul>
    <div>
        <div id="grid_messages" style="text-align: center"></div>
    </div>
</div>

<script class="grid_messages_columns">
    var fields = [{
        title: "#",
        field: "ID",
        width: 50
    }, {
        title: "姓名",
        field: "RealName",
        width: 100
    }, {
        title: "手机",
        field: "Mobile",
        width: 100
    }, {
        title: "邮箱",
        field: "Email",
        width: 200
    }, {
        title: "内容",
        field: "Description",
        width: 300
    }, {
        title: "日期",
        template: "#=kendo.toString(kendo.parseDate(CreatedOn),'yyyy-MM-dd')#",
        width: 100
    }, {
        title: "操作",
        template: "#=GetOperations(ID)#",
        attributes: { style: "text-align:left" }
    }];

    function GetOperations(id) {
        var html = "<button class='k-button' onclick=\"Delete(" + id + ")\"><span class='k-icon k-i-close'></span><span>删除</span></button>";
        return html;
    }

    function Delete(id) {
        if (confirm("真的要删除这个留言吗?")) {
            Whale.Remote.Operation({
                url: "/Admin/Fun/DeleteMessage",
                parameters: { id: id },
                success: function (result) {
                    if ($("#grid_messages").length > 0)
                        $("#grid_messages").data("kendoGrid").dataSource.read();
                },
                error: function (msg) {
                    wndGeneralInformation.content(msg).open();
                }
            });
        }
    }
</script>

<script class="grid_config">
    $(function () {
        $("#grid_messages").kendoGrid({
            columns: fields,
            dataSource: Whale.dataSource({
                url: "/Admin/Fun/GetMessages",
                pageSize: 10
            }),
            pageable: {
                messages: {
                    empty: "暂无数据"
                }
            },
            dataBound: function (e) {
                //让表头居中
                $("th.k-header").attr("style", "text-align:center; font-weight:bold;");
            }
        });
    });

    function Filters() {
        $("#grid_messages").data("kendoGrid").dataSource.page(0);
    }
</script>
